package com.springboot.asyn.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.internet.MimeMessage;
import java.io.File;

@Component
public class Send2 {
    @Autowired
    JavaMailSenderImpl javaMailSender;

    public void send2() throws Exception{
        Logger logger = LoggerFactory.getLogger(Send2.class);
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
        helper.setTo("c18245842939@163.com");
        helper.setFrom("1040395857@qq.com");

        helper.setSubject("消息头");
        helper.setText("" +
                "<b style='color:red'>今晚不开会了!</b> <img src='src\\main\\resources\\static\\1.jpg' alt='丢失'></img>",true);

        helper.addAttachment("附加",new File("C:\\Users\\Administrator\\Desktop\\1.jpg"));
        javaMailSender.send(mimeMessage);
        logger.info("执行完毕");
    }
}
